package com.zd.web.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.zd.entity.Writer;
import com.zd.service.WriterService;
import com.zd.service.impl.WriterServiceImpl;

/**
 * Servlet implementation class writerLoginServlet
 */
@WebServlet("/writerLoginServlet")
public class writerLoginServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
   
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		request.setCharacterEncoding("UTF-8");
		response.setCharacterEncoding("UTF-8");
		String writerName=request.getParameter("userId");
		String writerPass=request.getParameter("userPass");
		WriterService ws=new WriterServiceImpl();
		Writer writer=ws.writerLogin(writerName,writerPass);
		HttpSession session=request.getSession();
		session.setAttribute("writer", writer);
		if (writer.getWriterId()==0) {
			request.getSession().setAttribute("mes","账号或密码有误，请检查");
			
			System.out.println("登录失败");
			response.sendRedirect("login.jsp");
			return;
		}
		
		request.getSession().setAttribute("mes","");
		response.sendRedirect("WriterCenterServlet");
	}

	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		
	}

}
